//
//  TJClockInRecardController.m
//  BaoDian
//
//  Created by mac on 2024/7/27.
//

#import "TJClockInRecardController.h"
#import "TJClockInRecardCell.h"
#import "TJEmptyDataHandler.h"
#import "TJVideoPlayController.h"

@interface TJClockInRecardController ()

@property (nonatomic, strong) TJEmptyDataHandler *emptyDataHandler;
@property (nonatomic, strong) NSMutableArray *datas;

@end

@implementation TJClockInRecardController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.title = @"打卡记录";
    
    [self.tableView registerClass:TJClockInRecardCell.class forCellReuseIdentifier:@"TJClockInRecardCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 171;
    self.tableView.contentInset = UIEdgeInsetsMake(16, 0, 0, 0);
    self.tableView.contentOffset = CGPointMake(0, -16);
    self.tableView.backgroundColor = self.view.backgroundColor;
    [self.tableView setSectionIndexColor:UIColor.tj_9B9B9BColor];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(KNavBarHight);
        make.left.right.bottom.offset(0);
    }];
    
    _emptyDataHandler = [TJEmptyDataHandler emptyDataHandleWithScrollView:self.tableView configuration:^TJEmptyDataType(TJEmptyDataModel * _Nonnull dataModel) {
        dataModel.text = @"你暂时还没有打卡记录";
        dataModel.iconName = @"clockInRecardEmpty";
        return TJEmptyDataTypeBase;
    }];
    
    [self loadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TJClockInRecardCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TJClockInRecardCell" forIndexPath:indexPath];
    TJClockInRecardModel *model = self.datas[indexPath.row];
    cell.model = model;
    TJWeakify(self)
    [cell setTapCoverImageViewBlock:^(UIImage *coverImage){
        TJVideoPlayController *videoPlayController = [[TJVideoPlayController alloc] init];
        videoPlayController.url = model.videoUrl;
        videoPlayController.coverImage = coverImage;
        [weakself presentViewController:videoPlayController animated:YES completion:nil];
    }];
    return cell;
}

- (NSMutableArray *)datas {
    if (!_datas) {
        _datas = [NSMutableArray array];
    }
    return _datas;
}


- (void)loadData {
    [TJMinePresent loadClockInRecardListWithPageIndex:1 complete:^(NSArray * _Nonnull datas, NSError * _Nullable error) {
        if (datas.count) {
            [self.datas removeAllObjects];
            [self.datas addObjectsFromArray:datas];
        }
        self.emptyDataHandler.canDisplay = YES;
        [self.tableView reloadData];
    }];
}
 

 
@end
